package com.project.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class ContextPress implements ServletContextListener {
    //创建上下文对象时触发
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("上下文创建");
        //得到上下文对象
        ServletContext context = sce.getServletContext();
        //在上下文对象中，绑定在线人数的共享数据
        context.setAttribute("number", 0);
    }
    //销毁上下文对象时触发
    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("上下文销毁");
    }
}
